# -*- coding: utf-8 -*-

# $Id: crud.py 2 2012-09-01 15:54:17Z alexis.roda.villalonga@gmail.com $


from dja_skel.skeletons.base import BaseModelViewSkel


class CRUDView(BaseModelViewSkel):
    variables = ("applabel", "ModelName")
    skeleton_path = "templates/crud"
    summary = "creates a set of CBV views that implement CRUD."

    def get_view_module_map(self):
        context = self._context
        module = "{}_crud".format(context["model_name"])
        return [
            ( # CREATE
              module,
              "{}_create_view".format(context["model_name"]),
                ),
            ( # DELETE
              module,
              "{}_delete_view".format(context["model_name"]),
                ),
            ( # UPDATE
              module,
              "{}_update_view".format(context["model_name"]),
                ),
            ( # READ
              module,
              "{}_list_view".format(context["model_name"]),
                ),
            ]

    def get_view_url_map(self):
        context = self._context
        return [
            ( # CREATE
              r"^{}/add/$".format(context["model_name"]),
              "{}_create_view".format(context["model_name"]),
              ),
            ( # DELETE
              r"^{}/(?P<pk>\d+)/delete/$".format(context["model_name"]),
              "{}_delete_view".format(context["model_name"]),
              ),
            ( # UPDATE
              r"^{}/(?P<pk>\d+)/edit/$".format(context["model_name"]),
              "{}_update_view".format(context["model_name"]),
              ),
            ( # READ
              r"^{}/list/$".format(context["model_name"]),
              "{}_list_view".format(context["model_name"]),
              ),
              ]
